package com.cjl.multi_thread;

import java.util.concurrent.Exchanger;

public class ExchangerTest {
    public static void main(String[] args) {
        Exchanger<Integer> exchanger = new Exchanger<>();

        new Thread(new Runnable() {
            @Override
            public void run() {
                Integer a = 10;
                try {
                    System.out.println("ExchangerTest.run after ex a "+exchanger.exchange(a));
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();

        new Thread(new Runnable() {
            @Override
            public void run() {
                Integer b = 20;
                try {
                    System.out.println("ExchangerTest.run after ex b "+exchanger.exchange(b));
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();
    }
}
